# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=ocaml-gitlab
pkgver=0.1.8
pkgrel=0
_pkgreal=gitlab
pkgdesc="GitLab APIv4 OCaml library"
url="https://github.com/tmcgilchrist/ocaml-gitlab"
arch="all !riscv64 !loongarch64" # ocaml
license="BSD-3-Clause"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-atd-dev
	ocaml-cmdliner-dev
	ocaml-cohttp-dev
	ocaml-fmt-dev
	ocaml-iso8601-dev
	ocaml-otoml-dev
	ocaml-stringext-dev
	ocaml-uri-dev
	ocaml-yojson-dev
	"
makedepends="
	$depends_dev
	dune
	ocaml
	ocaml-menhir
	"
checkdepends="ocaml-alcotest-dev"
options="!check" # requires unpackaged ocaml-mdx
subpackages="
	olab
	$pkgname-dev
	"
source="$pkgname-$pkgver.tar.bz2::https://github.com/tmcgilchrist/ocaml-gitlab/releases/download/$pkgver/gitlab-$pkgver.tbz
	rename-to-olab.patch
	"
builddir="$srcdir/$_pkgreal-$pkgver"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build --verbose \
		-p gitlab,gitlab-unix,lab
}

check() {
	dune runtest --build-dir=.testenv --verbose \
		-p gitlab,gitlab-unix,lab
}

package() {
	dune install --destdir="$pkgdir" --docdir=/.omit \
		gitlab gitlab-unix lab
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

olab() {
	pkgdesc="$pkgdesc (command line tool)"
	depends=

	amove usr/bin/olab
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
04c5c7131fa5a630edd0d2c605084fb37bb6a4d875b208450bf3b3fb70dc17da0f9ed8de04271e4eea62168d77dbcdda139aa7fe1a40f06f6c6cfb4407c47680  ocaml-gitlab-0.1.8.tar.bz2
c4d765e2824e72acab9b0b810ac8c6b1a8a25c46477009bebaf8572319fa9d5ba83b5c9296d24fb41162ed20f8ebc2dfe5c9467135b25865ee4fdfdf2b481660  rename-to-olab.patch
"
